package com.pyk.mapper;


import com.pyk.entity.Homework;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HomeworkMapper {

    /*
    * 查询所有作业
    * */
    @Select("select * from homework")
    List<Homework> list();

    /*
    * 新增作业
    * */
    @Insert("insert into homework(title, description, due_date, type, course_id, total_score, status, creator,create_time,update_time) values " +
            "(#{title},#{description},#{dueDate},#{type},#{courseId},#{totalScore},#{status},#{creator},#{createTime},#{updateTime})")
    void insert(Homework homework);

    /*
    * 删除作业
    * */
    @Delete("delete from homework where homework_id = #{homeworkId}")
    void deleteHomeworkById(Integer homeworkId);

    /*
    * 修改作业
    * */
    @Select("select * from homework where homework_id = #{homeworkId}")
    Homework getById(Integer homeworkId);

    @Update("update homework set title = #{title},description = #{description},due_date = #{dueDate},type = #{type},course_id = #{courseId}," +
            "total_score = #{totalScore},status = #{status},creator = #{creator},create_time = #{createTime},update_time = #{updateTime} where homework_id = #{homeworkId}")
    void update(Homework homework);


    /*
    * 新增作业，题目
    * */
    @Insert("INSERT INTO homework (title, description, due_date, type, course_id, total_score, status, creator) VALUES (#{title}, #{description}, #{dueDate}, #{type}, #{courseId}, #{totalScore}, #{status}, #{creator})")
    @Options(useGeneratedKeys = true, keyProperty = "homeworkId")
    void InsertHomework(Homework homework);
}
